<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        nav {
            width: 100%;
            background-color: darkgrey;
            height: 40px;
        }

        nav>ul {
            background-color: burlywood;
            height: 40px;
            list-style: none;
            display: flex;
            /* 左右居中 */
            justify-content: center;
            align-items: center;
            /* 找到离二级菜单最近的且宽度是100%的父标签 */
            position: relative;
        }

        nav>ul>li {
            margin: 0 20px;
        }

        /* 二级菜单 */
        .sub-menu {
            /* 定位的标签，宽度会从100%变成靠内容撑开，需要手动设置100% */
            width: 100%;
            height: 280px;
            background-color: brown;
            position: absolute;
            top: 40px;
            left: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            /* 标签消失 */
            display: none;
        }

        .sub-item {
            width: 160px;
            height: 200px;
            background-color: #fff;
            border: 1px solid;
            margin: 0 10px;
        }

        .active:hover .sub-menu {
            display: flex;
        }
    </style>
</head>

<body>
    <!-- 导航菜单的最外层：宽度100% -->
    <nav>
        <ul>
            <li>
                <a href="#">首页</a>
            </li>

            <!-- 鼠标hover在第二个li上，出现二级菜单 -->
            <li class="active">
                <a href="#">所有商品</a>
                <!-- 二级菜单：作为li的子标签 -->
                <div class="sub-menu">
                    <div class="sub-item"></div>
                    <div class="sub-item"></div>
                    <div class="sub-item"></div>
                    <div class="sub-item"></div>
                </div>
            </li>

            <li>
                <a href="#">墙饰壁挂</a>
            </li>
        </ul>
    </nav>
</body>

</html>